<template>
  <div>
    <headNav title="学生证信息" ></headNav>
    <div class="bigDivCss" v-for="(val, index) in certificatesList" :key="index" >
      <div class="imgCss" >
        <img v-if="!val.portraitImgUrl" src="@/assets/img/default_heads.png" mode="" >
        <img v-else :src="val.portraitImgUrl" mode="" >
      </div>
      <div class="flexHeight middleDiv" >
        <span class="nameCss" >{{val.studentName}}</span>
        <span style="margin-top: 0.3rem;" >学生证号：{{val.deviceNo}}</span>
        <span style="margin-top: 0.1rem;" >手机号：{{val.phone}}</span>
      </div>
      <div class="flexHeight rightDiv" >
        <div style="display: flex; margin-top: 0.4rem;" v-if="val.deviceNo && val.phone" >
          <!-- <img src="@/assets/img/my/0%.png" mode="" v-if="val.devicePower == 0" >
          <img src="@/assets/img/my/1%.png" mode="" v-if="val.devicePower >= 1 && val.devicePower <= 10" >
          <img src="@/assets/img/my/11%.png" mode="" v-if="val.devicePower >= 11 && val.devicePower <= 20" >
          <img src="@/assets/img/my/21%.png" mode="" v-if="val.devicePower >= 21 && val.devicePower <= 50"  >
          <img src="@/assets/img/my/51%.png" mode="" v-if="val.devicePower >= 51 && val.devicePower <= 60"  >
          <img src="@/assets/img/my/61%.png" mode="" v-if="val.devicePower >= 61 && val.devicePower <= 80"  >
          <img src="@/assets/img/my/81%.png" mode="" v-if="val.devicePower >= 81 && val.devicePower <= 100"  >
          <span>{{val.devicePower}}%</span> -->
        </div>
        <div class="flexCenter labelCss" v-if="!val.phone && val.deviceNo" >待激活</div>
        <button type="default" v-if="val.deviceNo" @click="jumpClick('设置亲情号码', val)" >设置亲情号码</button>
        <span  v-if="val.deviceNo" @click="jumpClick('编辑绑定学生', val)" style="margin-top: 0.2rem; font-size: 0.26rem; color: #14CC8D;" >编辑</span>
        <button type="default" style="background: #14CC8D;" v-if="!val.deviceNo" @click="jumpClick('绑定学生', val)" >绑定学生</button>
      </div>
    </div>
  </div>
</template>

<script>
import headNav from '@/components/headNav/headNav.vue'
import { mapActions, mapState, mapGetters, mapMutations } from 'vuex'
import { getAllEquipmentListApi } from '@/api/myNewApi'
export default {
  components: {
    headNav,
  },
  computed: {
    ...mapState({
      studentId: state => state.user.studentId,
      roleCode: state => state.user.roleCode
    })
  },
  data () {
    return {
      certificatesList: []
    }
  },
  methods: {
    // 按钮跳转
    jumpClick(e, val) {
      if (e == '编辑绑定学生' && val.phone) {
        this.$vux.toast.text('该卡已激活，若需要更变请联系客服', 'middle')
        return
      }

      if (e == '设置亲情号码' && !val.phone) {
        this.$vux.toast.text('待激活状态无法设置亲情号码，请通过学生证开机实现激活操作', 'middle')
        return
      }
      localStorage.studentIDCard = e
      localStorage.localBindingDevice = JSON.stringify(val)
      this.$router.push('setUpCard')
    }
  },
  async mounted() {
    let res = await getAllEquipmentListApi()
    this.certificatesList = res
    console.log(res)
  }
}
</script>

<style lang="less" scoped >
 .rightDiv {
   width: 1.8rem;
   height: 100%;
   font-size: 0.24rem;
   justify-content: center;
   align-items: center;
   position: relative;
   .labelCss {
     background: #FFF0EE;
     width: 1rem;
     height: 0.5rem;
     position: absolute;
     top: 0;
     right: -0.2rem;
     border-radius: 0.15rem;
     color: #FF1800;
   }
   img {
     width: 0.44rem;
     height: 0.22rem;
     margin: 0.05rem 0.1rem 0 0;
   }
   button {
     width: 1.9rem;
     height: 0.55rem;
     color: #FFF;
     background: #128FEF;
     border-radius: 0.28rem;
     margin-top: 0.2rem;
     border: 0;
     font-size: 0.22rem;
   }
 }

.bigDivCss {
  width: 6.6rem;
  height: 2.2rem;
  background: #FFF;
  border-radius: 0.15rem;
  margin: 0.2rem 0 0 0.3rem;
  display: flex;
  .imgCss {
    width: 1.1rem;
    height: 100%;
    display: flex;
    justify-content: center;
    img {
      width: 0.7rem;
      height: 0.7rem;
      margin-top: 0.2rem;
      border-radius: 2rem;
      object-fit: cover;
    }
  }
  .middleDiv {
    width: 3.5rem;
    height: 100%;
    font-size: 0.24rem;
    color: #666666;
    .nameCss {
      font-size: 0.32rem;
      color: #000;
      font-weight: 600;
      margin-top: 0.3rem;
    }
  }
}

.flexCenter {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flexHeight {
  display: flex;
  flex-direction: column;
}

.flexAlign {
  display: flex;
  align-items: center;
}

.flexEdge {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
